<template>
  <nut-navbar :title="title" fixed safe-area-inset-top @click-back="routeBack">
    <template #left>
      <RectLeft />
    </template>
    <template #right>
      <div v-if="hasRight" @click="emits('save')">保存</div>
    </template>
  </nut-navbar>
</template>

<script setup>
import { defineProps, defineEmits } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
import { RectLeft } from "@nutui/icons-vue";

// 属性
const props = defineProps({
  title: {
    type: String,
  },
  hasRight: {
    type: Boolean,
  },
  replaceUrl: {
    type: String,
  },
});

// 方法
const emits = defineEmits(["save"]);

// 返回
const routeBack = () => {
  if (props.replaceUrl) {
    router.replace("/");
  } else {
    router.back();
  }
};
</script>

<style lang="less" scoped>
</style>
